//https://www.bilibili.com/video/BV1d54y1f7B3/?spm_id_from=333.337.search-card.all.click&vd_source=d6fe65f095f01f05591e89d810720ccc
// 2024-10-19

import java.util.HashMap;
import java.util.Map;

public class P013_斐波那契数列_空间换时间 {

    public static void main(String[] args) {
        System.out.println(fib(20));
    }

    //0,1,1,2,3,5,8.....

    static Map<Integer,Integer> map = new HashMap<>();
    private static int fib(int n) {
        if (n == 0 || n == 1) return n;
        if (map.containsKey(n)) {
            return map.get(n);
        }else {
            int fn = fib(n - 1) + fib(n - 2);
            map.put(n,fn);
            return fn;
        }
    }
}
